//
//  FormalTwoViewController.m
//  LoanOne
//
//  Created by WangZhenyu on 2017/10/5.
//  Copyright © 2017年 WangZhenyu. All rights reserved.
//

#import "FormalTwoViewController.h"
#import "FormalTabBar.h"
#import "LoadConfig.h"
#import "FormalLoanViewController.h"
#import "SGPagingView.h"

@interface FormalTwoViewController ()<SGPageTitleViewDelegate, SGPageContentViewDelegate>{
    FormalTabBar                 *tabBarView;
}

@property (nonatomic, strong) SGPageTitleView *pageTitleView;
@property (nonatomic, strong) SGPageContentView *pageContentView;

@end

@implementation FormalTwoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"贷款";
    tabBarView = [FormalTabBar sharedFormalTabBar];
    [self.navigationItem setHidesBackButton:YES];
    
    [self setupPageView];

    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.fd_interactivePopDisabled = YES;
    [self.view addSubview:tabBarView];
    [tabBarView setCurrentViewControllerIndex:2];
    
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.fd_interactivePopDisabled = NO;
}

- (void)setupPageView {
    NSArray *array = [[LoadConfig shareStance] getCategories];
    NSMutableArray *viewConMutArr = [NSMutableArray array];
    NSMutableArray *titleMutArr = [NSMutableArray array];
    for (NSInteger i = [array count] - 1; i >= 0 ; i--) {
        FormalLoanViewController *viewCon = [[FormalLoanViewController alloc] initWithNibName:@"FormalLoanViewController" bundle:nil];
        [viewConMutArr addObject:viewCon];
        viewCon.categoryId = [NSString stringWithFormat:@"%@", [[array objectAtIndex:i] objectForKey:@"id"]];
        [titleMutArr addObject:[[array objectAtIndex:i] objectForKey:@"title"]];
    }
    CGFloat contentViewHeight = SCREEN_HEIGHT_DEVICE - 104 - IS_iPhoneX_Top;
    self.pageContentView = [[SGPageContentView alloc] initWithFrame:CGRectMake(0, 104 + IS_iPhoneX_Top, SCREEN_WIDTH_DEVICE, contentViewHeight - IS_iPhoneX_Bottom - 50) parentVC:self childVCs:viewConMutArr];
    self.pageContentView.delegatePageContentView = self;
    [self.view addSubview:self.pageContentView];

    /// pageTitleView
    self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, 64 + IS_iPhoneX_Top, SCREEN_WIDTH_DEVICE, 40) delegate:self titleNames:titleMutArr];
    self.pageTitleView.titleColorStateNormal = TextGrayColor;
    self.pageTitleView.titleColorStateSelected = FormalThemeColor;
    self.pageTitleView.isShowIndicator = NO;
    self.pageTitleView.isOpenTitleTextZoom = YES;
    [self.view addSubview:self.pageTitleView];
}

- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    [self.pageContentView setPageCententViewCurrentIndex:selectedIndex];
}

- (void)pageContentView:(SGPageContentView *)pageContentView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
    [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
}
@end
